<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" arrow :key="index" @click="changeMerchants(item)">
				<view class="line">
					<view class="line1">
						<fui-tag v-if="item.active" type="success" :padding="['8rpx','16rpx']" :marginRight="10">当前</fui-tag>
						<fui-text :text="item.merch_name" type="black" size="28" block></fui-text>
					</view>
					<merch-balance :show-title="true" :balance="parseNumber(item.balance)" :settle_type="item.settle_type"></merch-balance>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<pcfooter></pcfooter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration,parseNumber} from '@/utils/util.js'
	import merchBalance from '@/components/common/merch-balance.vue';
	import pcfooter from '@/components/common/pcfooter.vue';
	export default {
		components:{
			merchBalance:merchBalance,
			pcfooter:pcfooter
		},
		data() {
			return {
				baseUrl:baseUrl,
				list:[],
			}
		},
		onLoad(e) {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			formatDuration,
			parseNumber,
			getList:function(callback=false){
				this.$get('merchant/common/merchants','',true).then(res=>{
					this.list=res;
					if(callback){
						callback();
					}
				});
			},
			changeMerchants:function(item){
				if(item.active){
					this.$navigateBack();
					return;
				}
				this.$post('merchant/common/change',{id:item.id},true,true).then(res=>{
					setTimeout(()=>{
						this.$reLaunch('merchant/index');
					},1500);
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.line{
	display: flex;
	justify-content: space-between;
	align-items: center;
	width:100%;
	.line1{
		display: flex;
	}
}
</style>